{{extend "message_admin_layout.html"}}

{{block sub_menu}}
{{sidemenu('sidemenu','messages/sent')}}
{{end}}

{{block content_main}}
{{use "jquery"}}
{{link "messages/messages.css"}}

<div class="row-fluid">
    <div class="span12" style="text-align:right;">
        <a href="{{=url_for('plugs.messages.views.MessageView.delete_all', send_flag='s')}}" 
            class="btn btn-danger"
            onclick="return confirm('{{=_("Are you sure to delete all sent messages?")}}');"
            >{{=_('Delete All')}}</a>
    </div>
</div>

<div class="list">  
    {{for x in objects:}}
    <div class="message" data-message="{{=x.id}}">  
        <div class="delete" data-click="delete" title="{{=_('Delete Message')}}">&times;</div>
        <div class="body">
            <div class="title"> 
                {{=_('At {} sent to {}').format(x.create_date, escape(x.user))}}
            </div> 
            <div class="details">
                <div class="user-image"><img src="{{<< x.user_image}}"/></div>
                <div class="message-text"> 
                    {{<< x.message}}
                </div> 
            </div> 
        </div>
    </div>
    {{pass}}
</div>
<div class="pagination">{{<< pagination}}</div>

<script type="text/javascript">
function get_id(el){
    var parent = $(el).parents('.message').get(0);
    return $(parent).data('message');
}
$(function(){
    $('[data-click="delete"]').click(function(){
        if(!confirm("{{=_('Are you sure to delete current message?')}}")) return;
        var $that = $(this);
        $.post('{{=url_for("plugs.messages.views.MessageView.delete")}}', {id:get_id($that)})
            .success(function(r){
                if (r.success){
                    window.location.reload();
                }else{
                    show_message(r.error);
                }
            });
    });
    
});
</script>
</div>
{{end}}
